#include <stdio.h>
using namespace std;

#define TRACE(x...) x
#define PRINT(x...) TRACE(printf(x))

#define rep(i,n) for (int i=0; i<n; i++)

int g, q;
int pil[110];
int pts[110];
int races[110][110];
int s, k;
int best;
int cont;
int tmp;

int main() {
	while (1) {
		scanf("%d %d", &g, &q);

		if (!g && !q) break;

		rep(i,g) rep(j,q) scanf("%d", &races[i][j]);
		
		scanf("%d", &s);

		rep(l, s) {
			scanf("%d", &k);

			rep(i,q) pts[i]=0;

			rep(i,k) scanf("%d", &pts[i]);		
			rep(i,q) pil[i]=0;
			
			rep(i,g) rep(j,q) pil[j]+=pts[races[i][j]-1];
	
			best=-1;
			cont=0;

			rep(i,q) if (best<pil[i]) best=pil[i];
			rep(i,q) if (best==pil[i]) cont++;

			tmp=0;

			rep(i,q) {
				if (best==pil[i]) {
					printf("%d", i+1);
					tmp++;
					if (tmp<cont) printf(" ");
				}				
			}

			printf("\n");
		}
	}

	return 0;
}
